package com.example.springboot_mybatis01.mapper;

import com.example.springboot_mybatis01.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    // 根据id删除数据
    @Delete("delete from emp where id=#{id}")
    public int delete_emp(int id);


    @Options(useGeneratedKeys = true, keyProperty = "id")   //返回主键值
    @Insert("insert into emp(username, name, gender, image, job, entrydate,dept_id,create_time,update_time) values" + "(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    public void add_emp(Emp emp);


    @Update("update emp set username = #{username},name = #{name},gender = #{gender},image= #{image},job= #{job}," + "entrydate= #{entrydate},dept_id=#{deptId},create_time= #{createTime},update_time= #{updateTime} where id= #{id}")
    public void update_emp(Emp emp);


//    @Select("select * from emp where id=#{id}")
//    public Emp getById(int id);

    //1-别名方式
//    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id=#{id}")
//    public Emp getById(int id);

    //2-注解方式
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "update_time", property = "updateTime"),
//            @Result(column = "create_time", property = "createTime")
//    })
//    @Select("select * from emp where id=#{id}")
//    public Emp getById(int id);


    //3- 在springboot 配置中开启自动驼峰转换
    @Select("select * from emp where id=#{id}")
    public Emp getById(int id);



    //多条件查询  使用xml配置方式。
    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);


}
